package com.atguigu.designpattern.singleton.type8;

public class SingletonTest08 {

    public static void main(String[] args) {
        System.out.println("单例模式-懒汉式-枚举（线程安全，懒加载，避免反序列化重新创建类，Effective Java推荐！！）");
        Singleton singleton1 = Singleton.INSTANCE;
        Singleton singleton2 = Singleton.INSTANCE;

        System.out.println(singleton1 == singleton2);
        System.out.println("singleton1 hashcode" + singleton1.hashCode());
        System.out.println("singleton2 hashcode" + singleton2.hashCode());

        singleton1.sayOk();
    }

}

enum  Singleton{
    INSTANCE;
    public  void sayOk() {
        System.out.println("OK");
    }
}
